package com.atjava.webspider.services;

import com.atjava.webspider.consts.Const;
import com.atjava.webspider.gui.SpiderMainGui;

public class ToolbarService {
	
	private static ToolbarService service;
	
	private ToolbarService (){}
	
	public static ToolbarService getInstance(){
		if(service == null){
			service = new ToolbarService();
		}
		return service;
	}

	public void setToolBar(int state){
		SpiderMainGui mainGui = SpiderMainGui.getInstance();
		boolean [] states = new boolean[5];
		switch(state){
		//已开始，正在下载
		case Const.TASK_STATE_DOWNING:
			states = new boolean[]{false,true,true,false};
			break;
		//已暂停
		case Const.TASK_STATE_PAUSED:
			states = new boolean[]{true,false,true,false};
			break;
		//已保存
		case Const.TASK_STATE_SAVED:
			states = new boolean[]{true,false,false,true};
		//已停止
		case Const.TASK_STATE_STOP:
			states = new boolean[]{true,false,false,true};
			break;
		//正在等待
		case Const.TASK_STATE_WATTING:
			states = new boolean[]{false,false,true,false};
			break;
		//已完成
		case Const.TASK_STATE_FINISHED:
			states = new boolean[]{true,false,false,true};
			break;
		default :
			states = new boolean[]{false,false,false,false};
			break;
		}
		mainGui.getJButtonStart().setEnabled(states[0]);
		mainGui.getJButtonPause().setEnabled(states[1]);
		mainGui.getJButtonStop().setEnabled(states[2]);
		mainGui.getJButtonProp().setEnabled(states[3]);
	}
}
